﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class TankBase : MonoBehaviour
{
    public int atk;
    public int def;
    public int maxHp;
    public int hp;

    public int moveSpeed = 10;
    public int roundSpeed = 100;
    public int headRoundSpeed = 100;

    public Transform Head;

    //死亡预设体
    public GameObject deadEff;

    public abstract void Fire();

    //被别人攻击
    public virtual void Wound(TankBase other)
    {
        int dmg = other.atk - def;
        if (dmg <= 0)
            return;
        hp -= dmg;
        if (hp <= 0)
        {
            Dead();
        }
    }

    public virtual void Dead()
    {
        Destroy(gameObject);
        //播放特效
        if (deadEff)
        {
            //实例化对象,顺便把位置和角度一起初始化
            GameObject effObj = Instantiate(deadEff, this.transform.position, this.transform.rotation);
            //由于该特效身上挂了音效,需要控制音效和音效音量
            AudioSource audioSource = effObj.GetComponent<AudioSource>();
            if (audioSource)
            {
                //根据音乐数据 设置音效大小和是否播放
                //设置音效大小
                audioSource.volume = GameDataMgr.Instance.musicData.audioVolume;
                //音效是否播放
                audioSource.mute = !GameDataMgr.Instance.musicData.audio;
                //避免没有勾选 Play on Awake
                audioSource.Play();
            }
        }
    }

    public virtual void AddProp(E_PropType type, int value)
    {

        switch (type)
        {
            case E_PropType.Hp:
                {
                    hp += value;
                    if (hp > maxHp)
                    {
                        hp = maxHp;
                    }
                    break;
                }
            case E_PropType.MaxHp:
                {
                    maxHp += value;
                    break;
                }
            case E_PropType.MoveSpeed:
                {
                    moveSpeed += value;
                    break;
                }
            case E_PropType.Atk:
                {
                    atk += value;
                    break;
                }
            case E_PropType.Def:
                {
                    def += value;
                    break;
                }
        }
    }
}
